package com.wordpress.fatecode.model;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.wordpress.fatecode.entity.Fazenda;
import com.wordpress.fatecode.jdbc.Conexao;

public class FazendaDAO {
	Connection connection;
	PreparedStatement stmt;
	ResultSet resultSet;
	
	public void salvar(Fazenda fazenda) {
		connection = new Conexao().getConnection();
		try {
			stmt = connection.prepareStatement("INSERT INTO FAZENDA(?, ?, ?)");
			// insert endereco fazenda
			stmt.setString(1, fazenda.getEndereco()
					.getLogradouro());
			stmt.setString(2, fazenda.getEndereco().getCidade());
			stmt.setString(3, fazenda.getEndereco().getEstado());
			
			stmt.execute();
			close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
		
		public void close() {
			try {
				if (resultSet != null)
					resultSet.close();

				if (stmt != null)
					stmt.close();

				if (connection != null)
					connection.close();

			} catch (SQLException ex) {
				ex.printStackTrace();
			}
		}
}
